<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Slardar script test</title>

  <script>
    ; (function (w, d, u, b, n, pc, ga, ae, po, s, p, e, t, pp) {
      // constants
      pc = 'precollect'
      ga = 'getAttribute'
      ae = 'addEventListener'
      po = 'PerformanceObserver'

      // placeholder function
      s = function (m) {
        p = [].slice.call(arguments)
        p.push(Date.now(), location.href)
        ;(m == pc ? s.p.a : s.q).push(p)
      }
      s.q = []
      s.p = { a: [] }
      w[n] = s

      // load sdk
      e = document.createElement('script')
      e.src = u + '?bid=' + b + '&globalName=' + n
      d.getElementsByTagName('head')[0].appendChild(e)

      // precollect error
      if (ae in w) {
        s.pcErr = function (e) {
          e = e || w.event
          t = e.target || e.srcElement
          if (t instanceof Element || t instanceof HTMLElement) {
            w[n](pc, 'st', { tagName: t.tagName, url: t[ga]('href') || t[ga]('src') })
          } else {
            w[n](pc, 'err', e.error)
          }
        }
        s.pcRej = function (e) {
          e = e || w.event
          w[n](pc, 'reject', e.reason || (e.detail && e.detail.reason))
        }
        w[ae]('error', s.pcErr, true)
        w[ae]('unhandledrejection', s.pcRej, true)
      }

      // precollect performance
      if ('PerformanceLongTaskTiming' in w) {
        pp = s.pp = { entries: [] }
        pp.o = new PerformanceObserver(function (l) {
          pp.entries = pp.entries.concat(l.getEntries)
        })
        pp.o.observe({ entryTypes: ['longtask', 'largest-contentful-paint', 'layout-shift'] })
      }
    })(
      window,
      document,
      'http://localhost:8080/cn/web-browser.js',
      'sdk-web-script',
      'SdkClient',
    )
    window.SdkClient('init', Cypress.env().config);
    window.SdkClient('on', 'init', () => {
    window.SdkClient?.getSender()?.setSize(0)
    window.SdkClient?.getSender()?.setWait(0)
  })
    window.SdkClient('context.set', 'precollect', true)
    window.SdkClient('context.set', 'stage', 1)
    window.SdkClient('sendEvent', {
      name: 'precollect-event'
    })
    window.SdkClient('context.set', 'stage', 2)
    window.SdkClient('captureException', new Error('precollect captureException'), { extraKey: 'extra info' })
    Promise.reject(new Error("Promise reject"))
    throw new Error('precollect error')
  </script>
</head>

<body>
  <link rel="stylesheet" href="https://m.toutiao.com/precollect.css" type="text/css" />
  <div id="app"></div>
  <script src="https://m.toutiao.com/precollect.js"></script>
  <!--empty resource error -->
  <script src=""></script>
  <!--  integrity 错误 -->
  <script src="http://tosv.byted.org/obj/infinity/olbgp.js"
    integrity="sha384-we28jtBRy+u+xjjqWbsGRnktXhlq6H/4Ca+3AnmfVUj2t1mGlTEd+HiVzsersTxf" crossorigin="anonymous">
    </script>
</body>

</html>